package efg.library.EJB;

import java.util.HashMap;

class LibraryPrincipal
{
	/***************************************************************************\
	 * Static
	\***************************************************************************/
	public static final String MANAGER = "manager";
	
	public static final String ADMINISTRATOR = "administrator";
	
	public static final String CASHIER = "cashier";
	
	private static HashMap<String, LibraryPrincipal> principals = new HashMap<String, LibraryPrincipal>();
	
	static
	{
		principals.put("eric", new LibraryPrincipal("eric", "geheim", new String[] {MANAGER, ADMINISTRATOR, CASHIER}));
		principals.put("fred", new LibraryPrincipal("fred", "geheim", new String[] {MANAGER}));
		principals.put("john", new LibraryPrincipal("john", "geheim", new String[] {ADMINISTRATOR}));
		principals.put("henk", new LibraryPrincipal("henk", "geheim", new String[] {CASHIER}));
	}
	
	static LibraryPrincipal findLibraryPrincipal(String name)
	{
		return principals.get(name);
	}
	
	/***************************************************************************\
	 * Object
	\***************************************************************************/
	private String name = null;
	
	private String password = null;
	
	private String[] roles = null;
	
	LibraryPrincipal(String newName, String newPassword, String[] newRoles)
	{
		name = newName;
		password = newPassword;
		roles = newRoles;
	}
	
	String getName()
	{
		return name;
	}
	
	String getPassword()
	{
		return password;
	}
	
	String[] getRoles()
	{
		return roles;
	}
	
	@Override
	public String toString()
	{
		String ret = "[" + name + ", " + password + ", " + roles[0];
		for (int i = 1; i < roles.length; i++)
		{
			ret += (", " + roles[i]);
		}
		ret += "]";
		return ret;
	}
}
